export default function mergeTableRow(tableData, keys) {
  const mergeTableRow = (list, key) => {
    const indexAttr = `_${key}Index`
    list.reduce((pre, cur) => {
      if (pre[key] === cur[key]) {
        cur[indexAttr] = 0
        pre[indexAttr] = pre[indexAttr] === undefined ? pre[indexAttr] + 1 : 2
        return pre
      } else {
        cur[indexAttr] = 1
        return cur
      }
    }, {})
  }
  Object.values(keys).forEach((key) => mergeTableRow(tableData, key))
  const spanMethod = ({ row, columnIndex }) => {
    const key = keys[columnIndex]
    if (key) {
      return {
        rowspan: row[`_${key}Index`], // 根据属性获取合并行数 0表示不显示，2表示显示两行
        colspan: 1, // 合并列数
      }
    }
  }
  return spanMethod
}
